package com.github.operationlog.command;

import com.github.operationlog.MethodAttribute;
import com.github.operationlog.output.OperationLogOutput;
import org.springframework.util.ReflectionUtils;

import java.lang.reflect.Method;

/**
 * Insert方法操作命令
 *
 * @author luke.luo
 */
public class InsertOperationCommand extends OperationCommand {

        public InsertOperationCommand(String table, Object target, MethodAttribute methodAttribute,
                                      Method findByIdMethod, OperationLogOutput operationLogOutput) {
            super(table, target, methodAttribute, findByIdMethod, operationLogOutput);
        }

        @Override
        public Object execute0(Object target, Method method, Object[] args, Object entityId) {
            Object returnValue = ReflectionUtils.invokeMethod(method, target, args);
            insertLog(entityId, buildEntityNewValue(entityId, args));
            return returnValue;
        }
    }